<?php $weekdays = array(
array('val'=>'0', 'str'=>"Chủ nhật"),
array('val'=>'1', 'str'=>"Hai"),
array('val'=>'2', 'str'=>"Ba"),
array('val'=>'3', 'str'=>"Tư"),
array('val'=>'4', 'str'=>"Năm"),
array('val'=>'5', 'str'=>"Sáu"),
array('val'=>'6', 'str'=>"Bảy")
); ?>

<section id="content">
<script type="text/javascript">

function backToIndex(subjectId)
	{
	$("#mainform").prop("action", "index/" + subjectId);
	return $("#mainform").submit();
	}

function sche_confirm(){
	isValidInfo = true;

	$("#startHourMsg").html("");
	$("#endHourMsg").html("");
	
	if(($("#txtScheduleMSdlStartHour").val() == "") || !($.isNumeric($("#txtScheduleMSdlStartHour").val())) ||
	   ($("#txtScheduleMSdlStartMin").val() == "") || !($.isNumeric($("#txtScheduleMSdlStartMin").val()))){
		$("#startHourMsg").html("(Vui lòng nhập giờ bắt đầu)");
		isValidInfo = false;
		}
	
	if(($("#txtScheduleMSdlEndHour").val() == "") || !($.isNumeric($("#txtScheduleMSdlEndHour").val())) ||
	   ($("#txtScheduleMSdlEndMin").val() == "") || !($.isNumeric($("#txtScheduleMSdlEndMin").val()))){
		$("#endHourMsg").html("(Vui lòng nhập giờ kết thúc)");
		isValidInfo = false;
		}

	startHour = parseInt($("#txtScheduleMSdlStartHour").val(), 10);
	endHour = parseInt($("#txtScheduleMSdlEndHour").val(), 10);
	startMin = parseInt($("#txtScheduleMSdlStartMin").val(), 10);
	endMin = parseInt($("#txtScheduleMSdlEndMin").val(), 10);
	
	if(startHour > endHour){
		$("#endHourMsg").html("(Giờ bắt đầu phải bé hơn hoặc bằng giờ kết thúc)");
		isValidInfo = false;
	}else if (startHour == endHour){
		if(startMin > endMin){
			$("#endHourMsg").html("(Giờ bắt đầu phải bé bé hơn hoặc bằng giờ kết thúc)");
			isValidInfo = false;
		}
	}
	
	if(isValidInfo){
		return $("#mainform").submit();
		}
	}

</script>

<div>
	<center><H1>Thêm lịch học</H1></center>
</div>

<form id="mainform" method="post" action="/it_center/Schedules/scheduleConfirm">
<input type="hidden" name="subjectId" value="<?php echo $subjectId;?>" />
<table id="edit_table">
<tr>
	<td class="edit_column" width="170">
		Ngày trong tuần
	</td>
	<td style="text-align: left;">
		<select id="ScheduleMSdlWeekDay" name="weekDay">
		<?php foreach ($weekdays as $weekday):?>
			<?php 
			$selected = "";
			if($weekDay == $weekday['val'])
				$selected = "selected";
			?>
			<option <?php echo $selected;?> value="<?php echo $weekday['val'];?>"><?php echo $weekday['str'];?></option>
		<?php endforeach; ?>
		<?php unset($weekday); ?>
	</select>
	</td>
</tr>
<tr>
	<td class="edit_column">
		Thời gian bắt đầu
	</td>
	<td style="text-align: left;">
		<input type="text" id="txtScheduleMSdlStartHour" name="startHour" value="<?php echo $startHour;?>"/> giờ
		<input type="text" id="txtScheduleMSdlStartMin" name="startMin" value="<?php echo $startMin;?>"/> phút
		<br/>
		<span id="startHourMsg" class="errMsg"></span>
	</td>
</tr>
<tr>
	<td class="edit_column">
		Thời gian kết thúc
	</td>
	<td style="text-align: left;">
		<input type="text" id="txtScheduleMSdlEndHour" name="endHour" value="<?php echo $endHour;?>"/> giờ
		<input type="text" id="txtScheduleMSdlEndMin" name="endMin" value="<?php echo $endMin;?>"/> phút
		<br/>
		<span id="endHourMsg" class="errMsg"></span>
	</td>
</tr>
<tr>
	<td colspan="2" style="text-align: center;">
		<button type="button" onclick="sche_confirm()">Xác nhận</button>
   		<button type="button" onclick="backToIndex(<?php echo $subjectId?>)">Quay lại</button>
	</td>
</tr>
</table>
</form>
</section>

